import matplotlib.pyplot as plt
import numpy as np
import os

def US():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    ind = np.arange(len(x_data))
    y_data1 = [0.7579864000000004, 0.8808456000000001, 0.8815849999999998, 0.7696546000000004, 0.8799038, 0.8799038, 0.8791284, 0.8565044000000002, 0.8711182, 0.7657729999999999, 0.39288760000000017, 0.39087799999999995]
    y_data2 = [0.73879, 0.87426, 0.87974, 0.7367, 0.87438, 0.87438, 0.87144, 0.84824, 0.862, 0.73856, 0.3734, 0.3722]
    w = 0.2
    ax = plt.subplot(111)
    a = ax.bar(ind,y_data1,width=0.2,align='center')
    b = ax.bar(ind+w,y_data2,width=0.2,align='center')
    ax.set_xticks(ind+w)
    ax.set_xticklabels( ('MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF') )
    plt.legend((a,b),('ave system utilization','worst system utilization'))
    plt.autoscale(tight=True)
    plt.title('The average/worst system utilization')
    plt.tight_layout()
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    US()